package com.oa.modules.approvalsec1.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.oa.modules.approvalsec1.entity.ProcessItemEntity;
import com.oa.modules.approvalsec1.entity.ProjectEntity;
import com.oa.modules.approvalsec1.entity.ProjectFileEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * project表
 *
 * @author jiangwei
 * @email 785297226@qq.com
 * @date 2021-12-14 09:49:22
 */
@Mapper
public interface ProjectFileDao extends BaseMapper<ProjectFileEntity> {


    /**
     * 查询总条数
     *
     * @author jiangwei
     * @email 785297226@qq.com
     * @date 2021-12-14 09:49:22
     * @Description 查询分页数据
     */
    @Select("<script>SELECT COUNT( 1 ) FROM (" +
            "select t1.* from xxx t1  " +
            "where " +
            "<if test = 'params != null '> "+
            "t1.`STATUS` = #{params.status} " +
            ") </if> TOTAL</script>")
    long findPage(@Param("params") Map<String, Object> params);

    /**
     * 查询分页数据
     *
     * @author jiangwei
     * @email 785297226@qq.com
     * @date 2021-12-14 09:49:22
     * @Description 查询分页数据
     */
    @Select("<script>select t1.* from xxx t1 " +
            "where " +
            "t1.`STATUS` = #{params.status} " +
            "ORDER BY t1.CREATE_DATE desc</script>")
    List<ProjectFileEntity> findRecords(IPage<ProjectFileEntity> page, @Param("params") Map<String, Object> params);

    /**
     * 根据项目赋码查询该项目下的所有节点文件
     *
     * @author jiangwei
     * @email 785297226@qq.com
     * @date 2021-12-14 09:49:22
     * @Description 查询分页数据
     */
    @Select("<script>select * from project_file a where a.url is not null and project_id = #{id} </script>")
    List<ProjectFileEntity> queryAllFile(@Param("coding") String id);

    /**
     * 查询已经有证照的节点
     * @param projectCoding
     * @param processId
     * @return
     */
    @Select("<script>" +
            "select pf.id,pf.item_id,pi.schedule_id node_id,ps.name nodeName from " +
            "project_file pf,process_item pi,project_schedule ps" +
            " where pf.item_id = pi.id and pi.schedule_id = ps.id " +
            "and pf.project_id = #{projectId} and pi.process_id = #{processId}" +
            "</script>")
    List<ProjectFileEntity> findNodeByProcessId(String projectId, Integer processId);
    @Select("<script>" +
            "select pi.id,pi.schedule_id,pi.process_id,ps.name " +
            "from process_item pi left join project_schedule ps " +
            "on pi.schedule_id = ps.id where pi.process_id = #{newProcessId}" +
            "</script>")
    List<ProcessItemEntity> findNodeByNewProcessId(Integer newProcessId);

    List<Integer> tj();

    List<HashMap> lxTj();

    List<HashMap> kgTj();

    List<HashMap> ndTj();

    List<HashMap> gtzzStateTj();

    List<HashMap> bbldStateTj();

    List<HashMap> tjProject(@Param("params") String name);

    List<ProjectEntity> bbldProject(@Param("params") Map<String, Object> params);

    List<HashMap> projectCountByType();

}
